#include <myheader.h>

/* Usage:  */
int main(int argc, char *argv[]){                                  
    char*port="8080";
    char*ip="192.168.74.128";
    int socket_fd=socket(AF_INET,SOCK_STREAM,0);
    

    struct sockaddr_in sock;
    sock.sin_addr.s_addr=inet_addr(ip);
    sock.sin_family=AF_INET;
    sock.sin_port=htons(atoi(port));
    int opt = 1;
    setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
    int ret=bind(socket_fd,(struct sockaddr*)&sock,sizeof(sock));
    ERROR_CHECK(ret,-1,"bind");
    
    listen(socket_fd,10);

    struct sockaddr_in sock_client;
    socklen_t len_client =sizeof(sock_client);
    int net_fd=accept(socket_fd,(struct sockaddr*)&sock_client,&len_client);
    printf("20\n");

    while(1){
        char buf[100]={0};
        ssize_t ret=recv(net_fd,buf,sizeof(buf),0);
        if(ret==0){
            break;
        }
        printf("buf:%s\n",buf);
        bzero(buf,sizeof(buf));
        read(STDIN_FILENO,buf,sizeof(buf));
        send(net_fd,buf,sizeof(buf),0);
    }
    close(net_fd);
    close(socket_fd);

    
    
    return 0;
}

